package org.ahuanlien.crm.service.impl;

import org.ahuanlien.crm.domain.Department;
import org.ahuanlien.crm.mapper.DepartmentMapper;
import org.ahuanlien.crm.query.QueryObject;
import org.ahuanlien.crm.service.IDepartmentService;
import org.ahuanlien.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class DepartmentServiceImpl implements IDepartmentService {

	@Autowired
	private DepartmentMapper departmentMapper;


	public List<Department> selectAll() {
		return departmentMapper.selectAll();
	}

	public PageResult query(QueryObject qo) {
		int count = departmentMapper.queryForCount(qo);
		if (count == 0) {
			return new PageResult(count, Collections.EMPTY_LIST);
		}
		List<Department> result = departmentMapper.queryForList(qo);
		return new PageResult(count, result);
	}

	public void saveOrUpdate(Department record) {
		if (record.getId() != null) {
			departmentMapper.updateByPrimaryKey(record);
		} else {
			departmentMapper.insert(record);
		}
	}

	public void deleteByPrimaryKey(Long id) {
		departmentMapper.deleteByPrimaryKey(id);
	}
}
